﻿Imports WindowsApplication1.saktiewebservice

Public Class Klant
    Private k_Id As Integer
    Private webser As New Service1SoapClient
    Public Property Id() As Integer
        Get
            Return k_Id
        End Get
        Set(ByVal value As Integer)
            k_Id = value
        End Set
    End Property
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        MainForm.txtKlantnaam.Text = ""
        MainForm.Show()
        Me.Close()
    End Sub
    Private Sub Klant_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MaximumSize = Me.Size
        Me.MinimumSize = Me.Size
        Me.StartPosition = FormStartPosition.CenterScreen
    End Sub

    Private Sub ProductenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductenToolStripMenuItem.Click
        Dim pr As New Producten
        Dim webser As New Service1SoapClient
        pr.klant_id = Id

        pr.lblKlantNaam.Text = txtNaam.Text + " " + txtAchternaam.Text

        pr.dgvProducten.DataSource = webser.getAlleProducten

        pr.StartPosition = FormStartPosition.CenterScreen

        pr.klant_form = Me

        pr.bestel_id = webser.createBestellingID()

        pr.Show()
        Me.Hide()
    End Sub

    Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        Dim teller As Integer = 0

        If Not txtGebruikersnaam.Text.Length = 0 Then
            teller += 1
        Else
            MsgBox("Gebruikersnaam mist")
        End If

        If Not txtNaam.Text.Length = 0 Then
            teller += 1
        Else
            MsgBox("Voornaam mist")
        End If

        If Not txtAchternaam.Text.Length = 0 Then
            teller += 1
        Else
            MsgBox("Achternaam mist")
        End If

        If Not txtAdres.Text.Length = 0 Then
            teller += 1
        Else
            MsgBox("Adres mist")
        End If

        If mtxtPostcode.MaskCompleted = False Then
            MsgBox("Postcode nog niet goed ingevuld ")
        Else
            teller += 1
        End If

        If Not txtTelefoon.Text.Length = 0 Then
            teller += 1
        Else
            MsgBox("Telefoon mist")
        End If

        If Not txtWoonplaats.Text.Length = 0 Then
            teller += 1
        Else
            MsgBox("Woonplaats mist")
        End If

        If Not txtOpmerkingen.Text.Length = 0 Then
            teller += 1
        Else
            MsgBox("Opmerking mist")
        End If

        If teller = 8 Then
            Dim k As New KlantBean
            k.Gebruikersnaam = txtGebruikersnaam.Text
            k.Naam = txtNaam.Text
            k.Achternaam = txtAchternaam.Text
            k.Adres = txtAdres.Text
            k.Postcode = mtxtPostcode.Text
            k.Woonplaats = txtWoonplaats.Text
            k.TelefoonNummer = txtTelefoon.Text
            k.Opmerking = txtOpmerkingen.Text
            If webser.createUser(k) = False Then
                MsgBox("Er ging iets fout met het aanmaken van het account.")
            Else
                MsgBox("Welkom " + txtNaam.Text + ". Je hebt je succesvol geregistreerd en je wordt weer terug gestuurd na het inlogscherm.")
                btnClose.PerformClick()
            End If

        Else
            teller = 0
        End If
    End Sub

    Private Sub txtGebruikersnaam_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGebruikersnaam.Leave
        If txtGebruikersnaam.ReadOnly = False Then
            If webser.checkUserName(txtGebruikersnaam.Text) = True Then
                MsgBox("Gebruikersnaam bestaat al.")
                txtGebruikersnaam.Focus()
            End If
        End If

    End Sub

    Private Sub Laatste25BestellingenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Laatste25BestellingenToolStripMenuItem.Click
        Dim bg As New BestelGeschiedenis

        bg.dgBestelgeschiedenis.DataSource = webser.getBestellingenByKlantID(Id())

        bg.StartPosition = FormStartPosition.CenterScreen

        bg.klant_form = Me

        bg.Show()
        Me.Hide()
    End Sub

    Private Sub tsmVoegProductToe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmVoegProductToe.Click
        Dim pt As New ProductToevoegen
        Dim webser As New Service1SoapClient

        pt.dgProducten.DataSource = webser.getAlleProducten()

        pt.StartPosition = FormStartPosition.CenterScreen

        pt.klant_form = Me

        pt.Show()
        Me.Hide()
    End Sub
End Class